import pygame
import random
class SmallEnemy(pygame.sprite.Sprite):
    def __init__(self,width,height):
        pygame.sprite.Sprite.__init__(self)
        
        self.width,self.height=width,height
        self.y_speed=4
        self.x_speed=random.randint(-4,4)
        self.image=pygame.transform.smoothscale(pygame.image.load('images/enemy1.png').convert_alpha(),(78,54))
        self.rect=self.image.get_rect()
        self.rect.left,self.rect.top=random.randint(0,self.width-self.rect.width),random.randint(-15*self.rect.height,-5*self.rect.height)
        self.mask=pygame.mask.from_surface(self.image)
        self.health=1
        self.alive=True
    def moveDown(self):
        if self.rect.top<self.height:
            self.rect.top+=self.y_speed
        else:
            self.alive=False
    def moveTransverse(self):
        self.rect.right+=self.x_speed
        if self.rect.right>=self.width or self.rect.left<=0:
            self.x_speed=-self.x_speed
            
    def reset(self):
        self.rect.left,self.rect.top=random.randint(0,self.width-self.rect.width),random.randint(-15*self.rect.height,-5*self.rect.height)
        self.health=1
        self.y_speed=6
        self.x_speed=random.randint(-4,4)
        self.alive=True

    def levelUp(self):
        self.y_speed+=1
        self.x_speed+=1
        
class MidEnemy(pygame.sprite.Sprite):
    def __init__(self,width,height):
        pygame.sprite.Sprite.__init__(self)
        
        self.width,self.height=width,height
        self.y_speed=3
        self.x_speed=3
        self.image=pygame.transform.smoothscale(pygame.image.load('images/enemy2_1.png').convert_alpha(),(124,136))
        self.image2=pygame.transform.smoothscale(pygame.image.load('images/enemy2_2.png').convert_alpha(),(124,136))
        self.image3=pygame.transform.smoothscale(pygame.image.load('images/enemy2_3.png').convert_alpha(),(124,136))
        self.rect=self.image.get_rect()
        self.rect.left,self.rect.top=random.randint(0,self.width-self.rect.width),random.randint(-30*self.rect.height,-20*self.rect.height)
        self.mask=pygame.mask.from_surface(self.image)
        self.health=10
        self.alive=True
    def moveDown(self):
        if self.rect.top<self.height:
            self.rect.top+=self.y_speed
        else:
            self.alive=False
    def moveTransverse(self):
        pass
        
    def reset(self):
        self.rect.left,self.rect.top=random.randint(0,self.width-self.rect.width),random.randint(-30*self.rect.height,-20*self.rect.height)
        self.health=10
        self.y_speed=3
        self.x_speed=3
        self.alive=True

    def levelUp(self):
        self.y_speed+=1
        self.x_speed+=1

class BigEnemy(pygame.sprite.Sprite):
    def __init__(self,width,height):
        pygame.sprite.Sprite.__init__(self)
        
        self.width,self.height=width,height
        self.y_speed=1
        self.x_speed=1
        self.image=pygame.transform.smoothscale(pygame.image.load('images/enemy3_1.png').convert_alpha(),(242,200))
        self.image2=pygame.transform.smoothscale(pygame.image.load('images/enemy3_2.png').convert_alpha(),(242,200))
        self.chain2=pygame.transform.smoothscale(pygame.image.load('images/enemy3_chain2.png').convert_alpha(),(242,200))
        self.rect=self.image.get_rect()
        self.rect.left,self.rect.top=random.randint(0,self.width-self.rect.width),random.randint(-40*self.rect.height,-30*self.rect.height)
        self.mask=pygame.mask.from_surface(self.image)
        self.health=100
        self.alive=True
        self.body_code=0
        self.chain_list=[]
    def moveDown(self):
        if self.rect.top<self.height:
            self.rect.top+=self.y_speed
        else:
            self.alive=False
    def moveTransverse(self):
        pass
    def produce_chain(self):
        self.chain_list=[]
        for i in range(1,int(self.rect.left/self.rect.width)+2):
            self.chain_list.append([self.rect.left-i*self.rect.width,self.rect.top])
        for j in range(int(self.rect.right/self.rect.width)+4):
            self.chain_list.append([self.rect.right+j*self.rect.width,self.rect.top])
        return self.chain_list
    def reset(self):
        self.rect.left,self.rect.top=random.randint(0,self.width-self.rect.width),random.randint(-40*self.rect.height,-30*self.rect.height)
        self.health=100
        self.chain_list=[]
        self.y_speed=1
        self.x_speed=1
        self.alive=True

    def levelUp(self):
        self.y_speed+=1
        self.x_speed+=1

class BigEnemyChain(pygame.sprite.Sprite):
    def __init__(self,width,height):
        pygame.sprite.Sprite.__init__(self)
        
        self.image=pygame.transform.smoothscale(pygame.image.load('images/enemy3_chain1.png').convert_alpha(),(242,200))
        self.rect=self.image.get_rect()
        self.rect.left,self.rect.top=2000,2000
        self.mask=pygame.mask.from_surface(self.image)
    def reset(self):
        self.rect.left,self.rect.top=2000,2000
        
